package se.no.noko.engine.core;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.os.Bundle;

public class RenderActivity extends Activity {

	protected RenderView renderView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		renderView = new RenderView(this);

		// Check if the system supports OpenGL ES 2.0.
		if (doesSupportOpenGLES2()) {
			// Request an OpenGL ES 2.0 compatible context.
			renderView.setEGLContextClientVersion(2);
			// Set the renderer to our demo renderer, defined below.
			renderView.setRenderer(new Scene());
		} else {
			// This is where you could create an OpenGL ES 1.x compatible
			// renderer if you wanted to support both ES 1 and ES 2.
			return;
		}

		setContentView(renderView);
	}

	@Override
	protected void onResume() {
		// The activity must call the GL surface view's onResume() on activity
		// onResume().
		super.onResume();
		renderView.onResume();
	}

	@Override
	protected void onPause() {
		// The activity must call the GL surface view's onPause() on activity
		// onPause().
		super.onPause();
		renderView.onPause();
	}

	private boolean doesSupportOpenGLES2() {
		final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
		final ConfigurationInfo configurationInfo = activityManager
				.getDeviceConfigurationInfo();
		final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
		return supportsEs2;
	}
}
